package cn.e4j.modular.api.controller;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.util.InvokeUtil;
import cn.e4j.modular.api.service.PjjsService;
import cn.e4j.modular.system.entity.SysUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yuan_rz on 2018/04/17.
 */
@RestController
@RequestMapping("api/wx/pjjs")
public class PjjsController {
    private static Logger logger = LoggerFactory.getLogger(PjjsController.class);

    @Autowired
    private PjjsService pjjsService;

    /**
     * 获取配件列表
     *
     * @return
     */
    @RequestMapping(value = "getPartListData")
    public ResponseData getPartListData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<>();
        SysUser currentUser = wapper.getSysUser();
        try {
            inDto.put("ENT", inDto.getString("ENT"));
            inDto.put("LANG", '2');
            inDto.put("GWAA001", currentUser.getACCOUNT());
//            list = pjjsService.getPartListData(wapper.getPage(),inDto);
            list = InvokeUtil.invokeBeanMethod("pjjsMapper,getPartListPage",wapper.getPage(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.error("服务器出小差了");
        }
        return ResponseData.success(list);
    }

    /**
     * 获取维修单号和服务客户
     *
     * @return
     */
    @RequestMapping(value = "getMmrtData")
    public ResponseData getMmrtData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<Dto>();
        try {
            list = pjjsService.getMmrtData(wapper.getPage(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.error("服务器出小差了");
        }
        return ResponseData.success(list);
    }

    /**
     * 配件寄送提交
     *
     * @return
     */
    @RequestMapping(value = "savePjjs")
    public ResponseData savePjjs(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        try {
            pjjsService.savePjjs(wapper.getSysUser(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseData.error("服务器出小差了");
        }
        return ResponseData.success();
    }
}
